package com.hp.gxw.service.impl;

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hp.gxw.constant.ReportEnum;
import com.hp.gxw.mapper.ReportMapper;
import com.hp.gxw.service.IReportService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author huangping
 * @since 2024-02-29
 */
@Service
public class ReportServiceImpl implements IReportService {

    @Resource
    private ReportMapper reportMapper;

    @Override
    public List<Map<String, Object>> getCols(String month, String type) {
        List<Map<String, Object>> list = new ArrayList<>();
        if(type.equals(ReportEnum.completed.getCode())){
            list = reportMapper.getCompletedCols(month);
        }else if(type.equals(ReportEnum.production.getCode())){
            list = reportMapper.getProductionCols(month);
        }
        return list;
    }

    @Override
    public Page<Map<String, Object>> getCompletedOrProductionData(String month, String type, Page<Object> page, QueryWrapper<Object> ew) {
        Page<Map<String, Object>> pageList = new Page<>();
        if(type.equals(ReportEnum.completed.getCode())){
            pageList = reportMapper.getCompletedData(page, month, ew);
        }else if(type.equals(ReportEnum.production.getCode())){
            pageList = reportMapper.getProductionData(page, month, ew);
        }
        return pageList;
    }

    @Override
    public List<Map<String, Object>> getCompletedOrProductionDataList(String month, String type, QueryWrapper<Object> ew) {
        List<Map<String, Object>> list = new ArrayList<>();
        if(type.equals(ReportEnum.completed.getCode())){
            list = reportMapper.getCompletedData(month, ew);
        }else if(type.equals(ReportEnum.production.getCode())){
            list = reportMapper.getProductionData(month, ew);
        }
        return list;
    }

    @Override
    public int checkTableExist(String month, String type) {
        int count = 0;
        if(type.equals(ReportEnum.completed.getCode())){
            count = reportMapper.checkTableExist("cost_count_completed_" + month);
        }else if(type.equals(ReportEnum.production.getCode())){
            count = reportMapper.checkTableExist("cost_count_production_"+month);
        }
        return count;
    }

    @Override
    public Page<JSONObject> getSaleSettlePage(Page<Object> page, QueryWrapper<Object> ew) {
        return reportMapper.getSaleSettlePage(page, ew);
    }

    @Override
    public List<Map<String, Object>> getSaleSettleList(QueryWrapper<Object> ew) {
        return reportMapper.getSaleSettleList(ew);
    }
}
